'use strict';

module.exports = () => async (ctx, next) => {
  const request = `${ctx.path} query${JSON.stringify(ctx.query)} body ${JSON.stringify(ctx.request.body)} user ${JSON.stringify(ctx.session ? ctx.session.user : '{}')}`;
  await next();
  let body;
  try {
    body = JSON.stringify(ctx.body);
  } catch (err) {
    body = 'stream';
  }
  const response = `statusCode ${ctx.response.status} body ${body}`;
  ctx.logger.info(JSON.stringify({ request, response }));
};
